package com.neusoft.elmboot.controller;

import com.neusoft.elmboot.po.wallet.WalletRule;
import com.neusoft.elmboot.service.WalletRuleService;
import com.neusoft.elmboot.util.response.ResultBody;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

@RestController
@RequestMapping("/elm/WalletRuleController")
public class WalletRuleController {
    
    @Resource
    private WalletRuleService walletRuleService;
    
    @PostMapping("/getRechargeRule")
    public ResultBody getRechargeRule() throws Exception {
        WalletRule rule = walletRuleService.getRechargeRule();
        return ResultBody.success(rule);
    }
    
    @PostMapping("/getWithdrawRule")
    public ResultBody getWithdrawRule() throws Exception {
        WalletRule rule = walletRuleService.getWithdrawRule();
        return ResultBody.success(rule);
    }
    
    @PostMapping("/updateRechargeRule")
    public ResultBody updateRechargeRule(@RequestParam BigDecimal rechargeLevel,
                                        @RequestParam BigDecimal rechargeGift) throws Exception {
        walletRuleService.updateRechargeRule(rechargeLevel, rechargeGift);
        return ResultBody.success();
    }
    
    @PostMapping("/updateWithdrawRule")
    public ResultBody updateWithdrawRule(@RequestParam BigDecimal withdrawRate) throws Exception {
        walletRuleService.updateWithdrawRule(withdrawRate);
        return ResultBody.success();
    }
    
    @PostMapping("/updateOverdraftRule")
    public ResultBody updateOverdraftRule(@RequestParam BigDecimal dailyInterestRate,
                                         @RequestParam BigDecimal minOverdraftAmount,
                                         @RequestParam BigDecimal maxOverdraftAmount) throws Exception {
        walletRuleService.updateOverdraftRule(dailyInterestRate, minOverdraftAmount, maxOverdraftAmount);
        return ResultBody.success();
    }
}

